<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords"
	content="Ibatis,参数,Codeasy,Code Easy,SQL格式化,SQL转化字符串,去掉首尾引号,格式化代码,SQL转化为一行,java字符,提高开发效率,java,代码,开发工具,辅助开发">
<meta http-equiv="description" content="Ibatis的输出SQL和参数组装">

	
<style type="text/css">

textarea {
	font-size: 14px;
}

.sqlResultDiv {
	width: 780px;
}

.sqlDiv {
	margin: 10px;
	border: 2px solid #FED901;
	padding: 10px;
}

.sqlDivHead {
	margin: 5px;
	font-size: 12px;
	width: 730px;
	text-align: right;
}

#mainDiv {
    width:1140px;margin-left:auto;margin-right:auto;
	margin-top: 0px;
}

#sqlsAndParams {
   width: 730px;
}

.c_t {
	margin: 20px;
}

#main_left {
	float: left;
}

#main_right {
	width: 320px;
	margin-left: 820px;
}

LEGEND {
	font-weight: bold;
	margin: 10px;
}

.title {
	font-size: 17px;
	font-weight: bold;
	text-align: center;
}
</style>
<title>IBatis日志SQL和参数组装器 - Codeasy</title>
</head>

<body>
	<s:include value="/common/header.jsp"></s:include>
	<div id="mainDiv">
		<div class="title">
			IBatis日志SQL和参数组装器 <a href="#"
				style="font-size: 12px; margin-left: 10px;">(使用帮助)</a>
		</div>
		
		<div id="main_left" class="main_detail">
				<FIELDSET>
					<LEGEND>请录入Ibatis的SQL和参数</LEGEND>
					 
					<table class="c_t">
						<tr>
							<td colspan="2"><textarea id="sqlsAndParams" name="content" 
									rows="12" style="word-wrap: normal;" onfocus="f_selAll(this);"></textarea>
							</td>
						</tr>
						<tr>
							<td colspan="2" style="text-align: center;"><input type="button"
								value="立即组装" onclick="f_deal();" /> <input type="button" value="清空"
								onclick="f_reset();" /></td>
						</tr>
					</table>
				</FIELDSET>			
				<FIELDSET>
					<LEGEND>处理结果</LEGEND>
					<div id="sqlResultDiv" class="sqlResultDiv"></div>
				</FIELDSET>
			</div>
			<div id="main_right" class="main_detail">
			<FIELDSET>
				<LEGEND>历史记录</LEGEND>
				<div>
					<ul id="historyList">
					</ul>
				</div>
			</FIELDSET>
			<FIELDSET>
				<LEGEND>演示例子</LEGEND>
				<ul id="demoList" style="font-size: 13px;">
					<li>
					    <textarea style='display:none;' id='historyInput_1000'>
SQL语句->Ibatis log sql : insert into ce_table  (id,         create,       modified,       trade_id,       type,       channel,       supplier_id,       channel_id,       order_no,       buyer_nick,       buyer_id,       seller_nick,       seller_num_id,       post_fee,       modified_fee,       discount_fee,       total_fee,       payment,       outer_gmt_time,       outer_gmt_modified,       gmt_pay,       finish,       outer_pay_status,       outer_delivery_status,       outer_status,       outer_status,       pay_status,       de_status,       ref_status,       remark,       receipt_remark,       time_remark,       buyer_remark,       remark,       rec_name,       prov,       city,       receiver_area,       receiver_address,       post,       phone,       receiver_mobile,       mailman_name,       mailman_prov,       mailman_city,       mailman_area,       mailman_address,       mailman_post,       mailman_phone,       mailman_mobile,       logistics_status,       gmt_logistics_modified,       operator,       creator,       operate,       shipping_type       )    values      (?,       sysdate,       sysdate,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       ?,       ?,       sysdate,       ?       )

SQL参数，以中括号括住参数，以逗号分割->IBatis sql params: [2811, 22334776486174, AGENT, 2, 233, 测试, 2010082400055416, baile02, null, null, null, 20.0, null, null, 980.0, 1000.0, 2010-08-24 13:14:52.0, 2011-08-24 19:57:08.0, 2010-08-23 13:15:39.0, null, null, null, null, WAIT_SELLER_SEND_GOODS, ALREADY_PAID, UNDELIVERED, REFUND_FINISH, null, null, null, -, null, 风见愁 , 浙江省, 杭州市, 西湖区, 华星路, 310000, null, 12587458745, null, null, null, null, null, null, null, null, N, 2011-09-06 16:46:15.921, SYNC_SYSTEM, SYNC_SYSTEM, express]
					    </textarea>
					    <a href="javascript:void(0);" onclick="f_getHistory(1000);">测试数据-单条SQL</a>
					</li>
					<li>
					    <textarea style='display:none;' id='historyInput_1001'>
SQL语句1->Ibatis log sql : insert into ce_table  (id,         create,       modified,       trade_id,       type,       channel,       supplier_id,       channel_id,       order_no,       buyer_nick,       buyer_id,       seller_nick,       seller_num_id,       post_fee,       modified_fee,       discount_fee,       total_fee,       payment,       outer_gmt_time,       outer_gmt_modified,       gmt_pay,       finish,       outer_pay_status,       outer_delivery_status,       outer_status,       outer_status,       pay_status,       de_status,       ref_status,       remark,       receipt_remark,       time_remark,       buyer_remark,       remark,       rec_name,       prov,       city,       receiver_area,       receiver_address,       post,       phone,       receiver_mobile,       mailman_name,       mailman_prov,       mailman_city,       mailman_area,       mailman_address,       mailman_post,       mailman_phone,       mailman_mobile,       logistics_status,       gmt_logistics_modified,       operator,       creator,       operate,       shipping_type       )    values      (?,       sysdate,       sysdate,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       to_date(?,'YYYY-MM-DD HH24:MI:SS'),       ?,       ?,       sysdate,       ?       )

SQL参数，以中括号括住参数，以逗号分割->IBatis sql params: [2811, 22334776486174, AGENT, 2, 233, 测试, 2010082400055416, baile02, null, null, null, 20.0, null, null, 980.0, 1000.0, 2010-08-24 13:14:52.0, 2011-08-24 19:57:08.0, 2010-08-23 13:15:39.0, null, null, null, null, WAIT_SELLER_SEND_GOODS, ALREADY_PAID, UNDELIVERED, REFUND_FINISH, null, null, null, -, null, 风见愁 , 浙江省, 杭州市, 西湖区, 华星路, 310000, null, 12587458745, null, null, null, null, null, null, null, null, N, 2011-09-06 16:46:15.921, SYNC_SYSTEM, SYNC_SYSTEM, express]
					   
SQL语句2->Ibatis log sql : delete from ce_table where id = ? and  buyer_nick = ? and pay_status = ?  

SQL参数，以中括号括住参数，以逗号分割->IBatis sql params: [2811, 风见愁, PAY]
					    </textarea>
					    <a href="javascript:void(0);" onclick="f_getHistory(1001);">测试数据-多条SQL</a>
					</li>
				</ul>
			</FIELDSET>
			</div>
	</div>
	<div style="clear: both;">
		<s:include value="/common/footer.jsp"></s:include>
	</div>
	 
</body>

<script type="text/javascript">

	var allSql = "";
	
    $(document).ready(function(){
    	 
    });

    function f_reset() {
	
	   document.getElementById("sqlsAndParams").value = "";
	   document.getElementById("output").value = "";
	}
    
    function f_deal() {
    	var sqlsAndParams = $("#sqlsAndParams").val();
    	if (sqlsAndParams == "") {
    		alert("请先录入Ibatis日志的SQL和参数再提交");
    		return;
    	}
    	
    	$("#sqlResultDiv").html("<img src='<%=path%>/images/common/ico_loading.gif'/> 系统处理中,请稍候...");
    	
    	$.ajax({ 
    		url: "<%=path%>/devtools/dealIbatisSqlFormat.do",
					data : {
						sqlsAndParams : sqlsAndParams
					},
					type : "POST",
					dataType : 'json',
					success : function(result) {
						var errorFlag = result.dataResult.errorFlag;
						if (errorFlag == 0) {
							$("#output").val(result.dataResult.resultMsg);
							var div = "";
							$.each(result.dataResult.resultList, function(i, obj) {
						        div = div
								+ "<div class='sqlDiv'><div id='sqlDivHead' class='sqlDivHead'>"
								+ "<a href='javascript:void(0);' onclick=\"f_copySql('sqlBody_"
								+ i
								+ "');\">复制单个</a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick='f_copyAllSql();'>复制所有</a></div><div id='sqlBody_" + i + "' class='sqlBody'>"
								+ obj + "</div></div>";
						        allSql = allSql + obj + "\n\n";
							});
							$("#sqlResultDiv").html(div);
							f_saveHistory(sqlsAndParams);
						} else {
							$("#sqlResultDiv").html("");
							alert("处理失败!原因:" + result.dataResult.errorMsg);
						}
					},
					error : function(er) {
						//BackErr(er);
					}
				});
	}

	function f_copySql(div) {
		f_copyText($("#" + div).text());
	}

	function f_reset() {
		$("#sqlsAndParams").val("");
		$("#sqlResultDiv").html("");

	}
	
	function f_copyAllSql() {
		f_copyText(allSql);
	}
	
	function f_getHistory(historyInputId){
		$("#sqlsAndParams").val($("#historyInput_" + historyInputId).val());
	}
	
	var historyCount = 0;
	var maxHistoryCount = 15;
	function f_saveHistory(sql){
		var ms = (new Date()).getTime();    
		if (historyCount < maxHistoryCount) {
			var liStr = "<li id='historyLi_"+ ms +"'><textarea style='display:none;' id='historyInput_" + ms + "'></textarea><a href=\"javascript:void(0);\" onclick=\"f_getHistory(" + ms + ");\">" + sql.substr(0,30) + "</a><a href='javascript:void(0);' style='margin-left:3px; font-size:11px;' onclick='f_delHistory(" +  ms + ")'>删除</a></li>";
			$("#historyList").prepend(liStr);
			$("#historyInput_" + ms).val(sql);
			historyCount++;
		} else {
			$("#historyList li:last-child").remove();
			historyCount--;
			f_saveHistory(sql);
		}
	}
	
	function f_delHistory(liId) {
		$("#historyLi_" + liId).remove();
		historyCount--;
	}
</script>

</html>
